'    Copyright (C) <2008>  <Kevin Pletinckx>
'
'    This program is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 3 of the License, or
'    (at your option) any later version.
'
'    This program is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.
'
'    You should have received a copy of the GNU General Public License
'    along with this program.  If not, see <http://www.gnu.org/licenses/>.

Public Class frmReela
    'Loads the ini file.
    Dim objIniFile As New IniFile(My.Settings.INI_Location)
    'Loads [Settings] from the ini file.
    Dim Title As String = objIniFile.GetString("Settings", "Title", "")
    Dim Image As String = objIniFile.GetString("Settings", "Image", "")
    Dim FirstTime As String = objIniFile.GetString("Settings", "FirstTime", "")

    'Loads [Names] from the ini file.
    Dim tButton1 As String = objIniFile.GetString("Names", "Button1", "")
    Dim tButton2 As String = objIniFile.GetString("Names", "Button2", "")
    Dim tButton3 As String = objIniFile.GetString("Names", "Button3", "")
    Dim tButton4 As String = objIniFile.GetString("Names", "Button4", "")
    Dim tButton5 As String = objIniFile.GetString("Names", "Button5", "")
    Dim tButton6 As String = objIniFile.GetString("Names", "Button6", "")
    Dim tButton7 As String = objIniFile.GetString("Names", "Button7", "")
    Dim tButton8 As String = objIniFile.GetString("Names", "Button8", "")
    Dim tButton9 As String = objIniFile.GetString("Names", "Button9", "")
    Dim tButton10 As String = objIniFile.GetString("Names", "Button10", "")
    Dim tButton11 As String = objIniFile.GetString("Names", "Button11", "")
    Dim tButton12 As String = objIniFile.GetString("Names", "Button12", "")
    Dim tButton13 As String = objIniFile.GetString("Names", "Button13", "")
    Dim tButton14 As String = objIniFile.GetString("Names", "Button14", "")
    Dim tButton15 As String = objIniFile.GetString("Names", "Button15", "")

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Loads the location.
        Dim TLoc1 As String = objIniFile.GetString("Locations", "Button1_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc1)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc1)
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Loads the location.
        Dim TLoc2 As String = objIniFile.GetString("Locations", "Button2_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc2)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc2)
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Loads the location.
        Dim TLoc3 As String = objIniFile.GetString("Locations", "Button3_loc", "")
        'Starts the file.
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc3)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc3)
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'Loads the location.
        Dim TLoc4 As String = objIniFile.GetString("Locations", "Button4_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc4)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc4)
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        'Loads the location.
        Dim TLoc5 As String = objIniFile.GetString("Locations", "Button5_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc5)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc5)
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        'Loads the location.
        Dim TLoc6 As String = objIniFile.GetString("Locations", "Button6_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc6)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc6)
        End If
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        'Loads the location.
        Dim TLoc7 As String = objIniFile.GetString("Locations", "Button7_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc7)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc7)
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        'Loads the location.
        Dim TLoc8 As String = objIniFile.GetString("Locations", "Button8_loc", "")
        'Starts the file.
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc8)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc8)
        End If
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        'Loads the location.
        Dim TLoc9 As String = objIniFile.GetString("Locations", "Button9_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc9)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc9)
        End If
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        'Loads the location.
        Dim TLoc10 As String = objIniFile.GetString("Locations", "Button10_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc10)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc10)
        End If
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        'Loads the location.
        Dim TLoc11 As String = objIniFile.GetString("Locations", "Button11_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc11)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc11)
        End If
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        'Loads the location.
        Dim TLoc12 As String = objIniFile.GetString("Locations", "Button12_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc12)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc12)
        End If
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        'Loads the location.
        Dim TLoc13 As String = objIniFile.GetString("Locations", "Button13_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc13)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc13)
        End If
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        'Loads the location.
        Dim TLoc14 As String = objIniFile.GetString("Locations", "Button14_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc14)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc14)
        End If
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        'Loads the location.
        Dim TLoc15 As String = objIniFile.GetString("Locations", "Button15_loc", "")
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(TLoc15)

        If fileExists = False Then
            MsgBox("File does not exist. Please change this in the settings window.", MsgBoxStyle.Critical, "File does not exist")
        Else
            'Starts the file.
            System.Diagnostics.Process.Start(TLoc15)
        End If
    End Sub

    Private Sub BtnSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettings.Click
        'Shows the loginform
        frmLogin.Show()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'Shuts down the program
        Me.Close()
    End Sub

    Private Sub frmFomTv_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        frmSplash.Show()
        Me.Opacity = 0
        If My.Settings.INI_Location = "" Then
            frmFirstTime.Show()
            Exit Sub
        End If

        'Checks if the INI is in the right folder.
        Dim INI As Boolean
        INI = My.Computer.FileSystem.FileExists(My.Settings.INI_Location)

        If INI = False Then
            MsgBox("No INI file found.", MsgBoxStyle.Critical)
            Me.Close()
        End If

        Dim fileContents As String
        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists("C:\version.txt")
        On Error Resume Next
        If fileExists = True Then
            My.Computer.FileSystem.DeleteFile("C:\version.txt", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        My.Computer.Network.DownloadFile("http://www.retroplay.nl/version.txt", "C:\version.txt")
        fileContents = My.Computer.FileSystem.ReadAllText("C:\version.txt")
        objIniFile.WriteString("Settings", "Version_current", System.Windows.Forms.Application.ProductVersion)
        objIniFile.WriteString("Settings", "Version_latest", fileContents)

        'Shows the title from the ini file.
        Me.Text = Title
        'Shows the button names from the ini file.
        Button1.Text = tButton1
        Button2.Text = tButton2
        Button3.Text = tButton3
        Button4.Text = tButton4
        Button5.Text = tButton5
        Button6.Text = tButton6
        Button7.Text = tButton7
        Button8.Text = tButton8
        Button9.Text = tButton9
        Button10.Text = tButton10
        Button11.Text = tButton11
        Button12.Text = tButton12
        Button13.Text = tButton13
        Button14.Text = tButton14
        Button15.Text = tButton15
        'Check for other logo, if empty, the default logo will be used.
        If Image <> "" Then
            imgTopLogo.Image = Reela.My.Resources.Resources.reela
        Else
            Exit Sub
        End If

    End Sub


End Class